package com.xtck.ha.system.api.factory;

import com.alibaba.fastjson2.JSONObject;
import com.xtck.ha.common.core.domain.R;
import com.xtck.ha.common.domain.system.api.object.TblDevice;
import com.xtck.ha.common.domain.system.api.object.TblSatellite;
import com.xtck.ha.common.domain.system.api.object.TblTmParam;
import com.xtck.ha.common.domain.system.api.object.vo.TblSatelliteVo;
import com.xtck.ha.system.api.RemoteObjectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理
 * 
 * @author hm
 */
@Component
public class RemoteObjectFallbackFactory implements FallbackFactory<RemoteObjectService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteObjectFallbackFactory.class);

    @Override
    public RemoteObjectService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteObjectService()
        {

            @Override
            public R<List<TblSatellite>> getSatList(TblSatellite tblSatellite, String source) {
                return R.fail("获取卫星列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<TblSatelliteVo>> obs(String source) {
                return R.fail("获取健康对象列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<TblDevice>> getDeviceList(TblDevice tblDevice, String source) {
                return R.fail("获取设备列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<TblTmParam>> getParamList(TblTmParam tblTmParam, String source) {
                return R.fail("获取参数列表失败:" + throwable.getMessage());
            }

            @Override
            public R mitigation(JSONObject jsonObject, String source) {
                return R.fail("插入异常预案库失败:" + throwable.getMessage());
            }
        };
    }
}
